// Tags: NetworkFlow
#include <cassert>
#include <cstdio>
#include <cstring>
#include <queue>

const int N = 1e2 + 5, inf = 0x3f3f3f3f;
int n, m, s, t, a[N], b[N], tmp[N << 1];
int e_cnt = 1, heads[N << 1], h[N << 1];
std::queue<int> q;

struct Edge {
  int v, nxt, f;
} e[N << 4];

inline void add(int u, int v, int f) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].f = f;
  e[++e_cnt].v = u, e[e_cnt].nxt = heads[v], heads[v] = e_cnt, e[e_cnt].f = 0;
}

inline bool bfs() {
  while (!q.empty()) q.pop();
  q.push(s);
  memset(h, 0, sizeof(h));
  h[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = heads[u], v; i; i = e[i].nxt) {
      if (!h[v = e[i].v] && e[i].f) {
        h[v] = h[u] + 1;
        if (v == t) return true;
        q.push(v);
      }
    }
  }
  return false;
}

int dinic(int u, int flow) {
  if (u == t) return flow;
  int rest = flow, k;
  for (int i = heads[u], v; i && rest; i = e[i].nxt) {
    if (h[v = e[i].v] == h[u] + 1 && e[i].f) {
      k = dinic(v, std::min(rest, e[i].f));
      if (!k) h[v] = 0;
      rest -= k;
      e[i].f -= k, e[i ^ 1].f += k;
    }
  }
  return flow - rest;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("CF546E Soldier and Traveling.in", "r", stdin);
  freopen("CF546E Soldier and Traveling.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  s = 0, t = (n << 1) + 1;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), add(s, i, a[i]), add(i, i + n, inf), a[n + 1] += a[i];
  for (int i = 1; i <= n; ++i)
    scanf("%d", &b[i]), add(i + n, t, b[i]), b[n + 1] += b[i];
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v + n, inf), add(v, u + n, inf);
  }
  int flow, maxflow = 0;
  while (bfs()) {
    if ((flow = dinic(s, inf))) { maxflow += flow; }
  }
  if (maxflow != b[n + 1] || a[n + 1] != b[n + 1]) {
    puts("NO");
  } else {
    puts("YES");
    for (int i = 1; i <= n; ++i) {
      memset(tmp, 0, sizeof(tmp));
      for (int j = heads[i], v; j; j = e[j].nxt) {
        if ((v = e[j].v) != s) { tmp[v] = e[j ^ 1].f; }
      }
      for (int j = 1; j <= n; ++j) printf("%d ", tmp[j + n]);
      putchar('\n');
    }
  }
  return 0;
}